<template>
  <div>
    <div class="tablesB">
      <ViewTitle text="基础信息" />

      <div>
        <el-table  v-loading="params.loading" :data="list" style="width: 100%">
          <el-table-column type="index" label="序号" width="50">
          </el-table-column>
          <template v-for="(item, index) in tableTitle">
           
            <el-table-column
             
              :prop="item.prop"
              :label="item.name"
              :key="index"
             
            >
            </el-table-column>
          </template>
            <el-table-column fixed="right" label="操作" width="120">
                <template slot-scope="scope">
                  <el-button
                    @click="detail(scope.row)"
                    type="text"
                    size="small"
                  >
                    修改
                  </el-button>
                  <el-button
                    @click="examine(scope.row)"
                    type="text"
                    size="small"
                  >
                    查看
                  </el-button>
                </template>
              </el-table-column>
        
        </el-table>
      </div>
        <div>
              <el-pagination
                class="fenye"
                :background="true"
                :current-page="params.page"
                :page-size="params.limit"
                layout="prev, pager, next"
                @current-change="handlePagination"
                :total="params.count"
              >
              </el-pagination>
            </div>
    </div>

      <div class="bl">
      <el-dialog
      :visible.sync="bl.show"
       v-if="bl.show"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        title="详情"
        :modal-append-to-body="true"
        :destroy-on-close="true"
      >
       <bldetail :thatF="this" ref="bllist"></bldetail>
      </el-dialog>
      
    </div>
    <el-dialog
      title="查看"
      :visible.sync="dialogVisible"
      width="100%"
      top="0"
      :before-close="handleClose"
    >
      <span>
        <iframeDemo :url="url" ref="iframeDemo" height="700px" />
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <iframeDemo
      :url="url"
      ref="iframeDemo"
      height="500px"
      style="display: none"
    />
  </div>
</template>
<script>
let t;

import ViewTitle from "@/forComponents/viewTitle/index.vue";
import { mapState } from "vuex";
import { Loading } from 'element-ui'; //项目已经全局引入element的话可以不单独引入
import bldetail from './detail.vue'
import { iframeUrl,http2   } from "@/utils/server.js";
import iframeDemo from "@/components/iframeDemo/index.vue";
export default {
  props: ["thatF"],

  data() {
    return {
       url: `${iframeUrl}/#/info?type=1`,
        bl:{
            show:false,
            dataDetail:{},
        },
      params:{
          loading:false,
          page:1,
          limit:20,
          count:0,
      },
      list: [],
      
      tableTitle: [
        {
          prop: "member_info.name",
          name: "患者",
        },

        {
          prop: "diagnosis", 
          name: "诊断",
        },
        {
          prop: "doctor_info.real_name",
          name: "医生",
        },
        {
          prop: "created_at",
          name: "开立时间",
        },
      ],
      dialogVisible:false,
    };
  },
  computed: {},
  mounted() {
    t = this;
    t.getList();
  },
  methods: {
      handleClose(){
        this.dialogVisible = false
      },
      detail(e){
         
          let d={
              patient_no:e.patient_no,
          }
     
            t['_API'].getClinic_doctorGetMedicalRecordDetail(d).then(res=>{
                if(res.code==200){
                      t.bl.dataDetail={
                        ...res.data,
                        name:res.data.member_info.name,
                        gender:res.data.member_info.gender,
                        birthday:res.data.member_info.birthday,
                        dept_name:res.data.doctor_info.dept_name,
                        real_name:res.data.doctor_info.real_name,
                        start_time:res.data.created_at,
                      }
                       t.bl.show=true;
                }
            })
            .catch(e=>{
              console.log(e)
            })
      },
      // 查看病历
      examine(e){
        let loading        //定义loading变量
        loading = Loading.service({
          lock: true,
          text: '加载中……',
          background: 'rgba(255,255,255, 0)'
        })
         let d={
              patient_no:e.patient_no,
          }
            // var http=`${http2}?tepid=72&is_pattern=2&uid=${data.id}&source=4&his_uid=${data.member_info.id}&real_name=${this.real_name}&tep_name="门诊病历"`
        
        // window.open(http,'_blank');
         t['_API'].getClinic_doctorGetMedicalRecordDetail(d).then(res=>{
          //  this.dialogVisible = true
          //  loading.close()
           let data = res.data
                    t['_API'].getByKey({key:'clinic_use_medical_record_tpl_id'}).then(res2=>{
                if(res2.code==200){
                    var clinic_use_medical_record_tpl_id= res2.data.clinic_use_medical_record_tpl_id
                    var http=`${http2}?tepid=${clinic_use_medical_record_tpl_id}&is_pattern=2&source=4&his_uid=${data.member_info.id}&real_name=${this.real_name}&tep_name=门诊病历&patient_no=${data.patient_no}`
        
        window.open(http,'_blank');
     
           loading.close()
                }
            })
            .catch(e=>{
              console.log(e)
            })
          //   let text = ""
          //   data.diagnosis.forEach((item,key)=>{
          //     if(key == data.diagnosis.length-1){
          //       text += item.name
          //     }else{
          //       text += (item.name + '&')
          //     }
          //   })
            // console.log(data.member_info,"现在的值")
            // this.url = `${iframeUrl}/#/info?type=2`
            // setTimeout(function(){
            //     t.$nextTick(function(){
            //     let json = {
            //       id:10,
            //       hospitalName:process.env.VUE_APP_HOSPITAL_API,
            //       main_desc:data.main_desc,
            //       medical_history:data.medical_history,
            //       family_history:data.family_history,
            //       check_result:data.check_result,
            //       allergy_history:data.allergy_history,
            //       body_check:data.body_check,
            //       medical_now:data.medical_now,
            //       remark:data.remark,
            //       spirit_check:data.spirit_check,
            //       treatment:data.treatment,
            //       with_user:data.with_user,
                  // name:data.member_info.name,
                //   member_Id:data.member_info.id,
                //   gender:data.member_info.gender == 1 ? '男' : data.member_info.gender == 2 ? '女' : '未知',
                //  age:data.member_info.age,
                //  birthday:data.member_info.birthday,
                //   address:data.member_info.address,
                //   patient_no:data.patient_no,
            //       dept_name:data.doctor_info.dept_name,
            //       real_name:data.doctor_info.real_name,
            //       created_at:data.created_at,
            //       look_type:data.look_type == 1 ? '初诊' : '复诊',
            //       with_user_name:"",
            //       with_user_phone:"",
            //       diagnosis:text,
            //       treatment:data.treatment,
            //       token:localStorage.getItem("token")
            //     };
            //     t.$refs.iframeDemo.handleEmit(json);
            //   });
            // }, 300);
        })
        
    },
      handlePagination(e){
          t.params.page=e;
          t.getList()
      },
    getList() {
     
      let d = {
        member_id: t.thatF.thatF.PatientInfoDatathird.member_id,
        page:t.params.page,
        limit:t.params.limit,
      };
      t.params.loading=true;
      t["_API"].getClinic_doctorGetMedicalRecord(d).then((res) => {
           t.params.loading=false;
            
            if(res.code==200){
                 t.list = res.data.list;
                 t.params.count=res.data.count;
            }
      });
    },
  },
  components: {
    ViewTitle,
    bldetail,
    iframeDemo
  },
};
</script>
<style lang='scss' scoped>

.bl{
    /deep/ .el-dialog{
        width: 100%;
        margin-top: 0 !important;
    // height: 100%;
    // overflow: scroll;
    }
    
}
</style>